<?php


namespace app\admin\model;

use GatewayWorker\Lib\Gateway;

class Notice extends Base
{
    /**
     * Desc: 发送站内信
     * User: 苏鹏
     * Date: 2023/10/16
     * Time: 0:11
     * @return void
     */
    public function sendInmail($data)
    {

        //组发
        if(empty($data['to_dep_id'])){
            return false;
        }
        //查询部门下所有人，将信息站内信表
        $save_data = [];
        $user_ids = RoleReUser::where('role_id', $data['to_dep_id'])->column('user_id');

        foreach($user_ids as $k=>$v)
        {
            $save_data[] = [
                'type' => $data['type'],
                'to_user_id' => $v,
                'to_dep_id' => $data['to_dep_id'],
                'content' =>$data['send_content']
            ];
        }

        if(!empty($save_data))
        {
            $this->saveAll($save_data);
            //发送长链接组推
            gateway_to_group($data['to_dep_id'], $data);
        }
        return true;
    }
}